package com.geekband.Test01;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Binder;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;

/**
 * Function:
 * Create date on 15/11/23.
 *
 * @author Conquer
 * @version 1.0
 */
public class MusicService extends Service {

    private static final String TAG = MusicService.class.getSimpleName();

    private MediaPlayer mMediaPlayer;
    private IBinder mIBinder = new LocalBinder();

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "onCreate");
        mMediaPlayer = MediaPlayer.create(this, R.raw.libai);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i(TAG, "onStartCommand");
        mMediaPlayer.start();
        return START_NOT_STICKY;
    }

    @Override
    public void onDestroy() {
        mMediaPlayer.stop();
        super.onDestroy();
        Log.i(TAG, "onDestroy");
    }


    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return mIBinder;
    }

    public class LocalBinder extends Binder {

        MusicService getService() {
            return MusicService.this;
        }
    }


    public int getMusicPlayProgress() {
        return 18;
    }

}
